<?php 
$servername = "localhost";
$username = "root";
$password = "svh123456";
$dbname = "csb";
 
// 创建连接
$conn = mysqli_connect($servername, $username, $password,$dbname);
 
// 检测连接
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "数据库连接成功";

$sql = "select jl from csbsjb";
$rst = mysqli_query($conn,$sql);
 ?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>实时更新数据的超声波图表演示</TITLE>
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/highcharts.js"></script>
</head>
<body>
<div id="container" style="width:700px;height:400px;margin:0 auto;"></div>
<div style="text-align:center;clear:both;">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>






<script type="text/javascript">

$(function () {                                                                     
$(document).ready(function() {                                                  
	Highcharts.setOptions({                                                     
		global: {                                                               
			useUTC: false                                                       
		}                                                                       
	});                                                                         
																				
	var chart;
	var i=0;
	//var arr=[2.52,2.33,2.35,7.19,3.69,3.5,3,3.3,3.2,3.2,3.5,3.6,3.6,3.0,3.5]; 

 var str="<?php

while($row=mysqli_fetch_assoc($rst)){
    
    echo $row['jl'];
print_r("|");
}
?>";
var arr=str.split("|");
                                                             
	$('#container').highcharts({                                                
		chart: {                                                                
			type: 'spline',                                                     
			animation: Highcharts.svg, // don't animate in old IE               
			marginRight: 10,                                                    
			events: {                                                           
				load: function() {                                              
																				
					// set up the updating of the chart each second             
					var series = this.series[0];                                
					setInterval(function() {                                    
						var x = (new Date()).getTime(); // current time         
							
						 
						var	y =parseFloat(arr[i++]); 
                     
						series.addPoint([x, y], true, true);                    
					}, 1000);                                                   
				}                                                               
			}                                                                   
		},                                                                      
		title: {                                                                
			text: '超声波动态走势图--1秒'                                            
		},                                                                      
		xAxis: {                                                                
			type: 'datetime',                                                   
			tickPixelInterval: 100                                              
		},                                                                      
		yAxis: {                                                                
			title: {                                                            
				text: '超声波动态走势图--1秒'                                                   
			},                                                                  
			plotLines: [{                                                       
				value: 0,                                                       
				width: 1,                                                       
				color: '#808080'                                                
			}]                                                                  
		},                                                                      
		tooltip: {                                                              
			formatter: function() {                                             
					return '<b>'+ this.series.name +'</b><br/>'+                
					Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
					Highcharts.numberFormat(this.y, 2);                         
			}                                                                   
		},                                                                      
		legend: {                                                               
			enabled: false                                                      
		},                                                                      
		exporting: {                                                            
			enabled: false                                                      
		},                                                                      
		series: [{                                                              
			name: 'Random data',                                                
			data: (function() {                                                 
				// generate an array of random data                             
				var data = [],                                                  
					time = (new Date()).getTime(),                              
					i;                                                          
																				
				for (i = -19; i <= 0; i++) {                                    
					data.push({                                                 
						x: time + i * 1000,                                     
						y: 1                                        
					});                                                         
				}                                                               
				return data;                                                    
			})()                                                                
		}]                                                                      
	});                                                                         
});                                                                             
																				
});     
</script>




<body onload="getArr()"></body>

</html>